home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 13 - 1997 (partial) / 13.05 May 97 / Appearance Folder / AppearanceHelpers.c next >
Encoding:
C/C++ Source or Header  |  1997-04-21  |  23.4 KB  |  840 lines  |  [TEXT/CWIE]

  1. /*
  2.      File:        AppearanceHelpers.c
  3.  
  4.      Contains:    Glue routines to simplify using Appearance controls, etc.
  5.  
  6.      Version:    Technology:    Appearance 1.0
  7.                  Release:    Tempo
  8.  
  9.      Copyright:    © 1997 by Apple Computer, Inc.  All rights reserved.
  10.   
  11. */
  12.  
  13. #include "Appearance.h"
  14. #include "AppearanceHelpers.h"
  15. #include "Assertions.h"
  16.  
  17. // Noone likes a mess. Here's some macros to help out.
  18.  
  19. #define ASSERT_ALIGNMENT( align )    \
  20.     ASSERT( ((align) == kControlBevelButtonAlignCenter) || ((align) == kControlBevelButtonAlignTop)    \
  21.             || ((align) == kControlBevelButtonAlignBottom) || ((align) == kControlBevelButtonAlignLeft)    \
  22.             || ((align) == kControlBevelButtonAlignRight) || ((align) == kControlBevelButtonAlignTopLeft) \
  23.             || ((align) == kControlBevelButtonAlignTopRight) || ((align) == kControlBevelButtonAlignBottomLeft) \
  24.             || ((align) == kControlBevelButtonAlignBottomRight) || ((align) == kControlBevelButtonAlignSysDirection) )
  25.  
  26. #define ASSERT_TEXT_ALIGNMENT( align )    \
  27.     ASSERT( ((align) == kControlBevelButtonAlignTextSysDirection) || ((align) == kControlBevelButtonAlignTextCenter)    \
  28.             || ((align) == kControlBevelButtonAlignTextFlushRight) || ((align) == kControlBevelButtonAlignTextFlushLeft) )
  29.  
  30. #define ASSERT_TEXT_PLACEMENT( align )    \
  31.     ASSERT( ((align) == kControlBevelButtonPlaceSysDirection) || ((align) == kControlBevelButtonPlaceToRightOfGraphic)    \
  32.             || ((align) == kControlBevelButtonPlaceToLeftOfGraphic) || ((align) == kControlBevelButtonPlaceBelowGraphic) \
  33.             || ((align) == kControlBevelButtonPlaceAboveGraphic) || ((align) == kControlBevelButtonPlaceNormally ) )
  34.  
  35.  
  36. #define MIN( a, b )        ( ( (a) < (b) ) ? (a) : (b) )
  37.  
  38. //—————————————————————————————————————————————————————————————————————————————
  39. //    • NewThemeMenu
  40. //—————————————————————————————————————————————————————————————————————————————
  41. //    Creates a theme-savvy menu on the fly. Since NewMenu assumes the usage of
  42. //    MDEF 0, we need to do a little fancy footwork to get around it. We get the
  43. //    theme MDEF and stuff the menuProc field of the menu with it.
  44. //
  45. pascal MenuHandle
  46. NewThemeMenu( SInt16 menuID, ConstStr255Param menuTitle )
  47. {
  48.     MenuHandle        menu;
  49.     
  50.     menu = NewMenu( menuID, menuTitle );
  51.     if ( menu )
  52.     {
  53.         Handle        themeDefProc = GetResource( 'MDEF', kMenuStdMenuProc );
  54.         
  55.         if ( themeDefProc )
  56.             (**menu).menuProc = themeDefProc;
  57.     }
  58.     return menu;
  59. }
  60.  
  61. //—————————————————————————————————————————————————————————————————————————————
  62. //    • GetEditTextText
  63. //—————————————————————————————————————————————————————————————————————————————
  64. //    Returns the text from an edit text control.
  65. //
  66. pascal OSStatus
  67. GetEditTextText( ControlHandle control, StringPtr text )
  68. {
  69.     Size        actualSize;
  70.     OSStatus    err;
  71.     
  72.     if ( control == nil )
  73.         return paramErr;
  74.         
  75.     if ( text == nil )
  76.         return paramErr;
  77.         
  78.     err = GetControlData( control, 0, kControlEditTextTextTag, 255, (Ptr)(text + 1), &actualSize );
  79.     if ( err == noErr )
  80.         text[0] = MIN( 255, actualSize );
  81.         
  82.     return err;
  83. }
  84.  
  85. //—————————————————————————————————————————————————————————————————————————————
  86. //    • SetEditTextText
  87. //—————————————————————————————————————————————————————————————————————————————
  88. //    Sets the text of an edit text control and optionally redraws it.
  89. //
  90. pascal OSStatus
  91. SetEditTextText( ControlHandle control, ConstStr255Param text, Boolean draw )
  92. {
  93.     OSStatus    err;
  94.     
  95.     if ( control == nil )
  96.         return paramErr;
  97.  
  98.     err = SetControlData( control, 0, kControlEditTextTextTag, text[0], (Ptr)(text+1) );
  99.     if ( (err == noErr) && draw )
  100.         DrawOneControl( control );
  101.     
  102.     return err;
  103. }
  104.  
  105. //—————————————————————————————————————————————————————————————————————————————
  106. //    • SetEditTextKeyFilter
  107. //—————————————————————————————————————————————————————————————————————————————
  108. //    Sets the text of an edit text control and optionally redraws it.
  109. //
  110. pascal OSStatus
  111. SetEditTextKeyFilter( ControlHandle control, ControlKeyFilterUPP filter )
  112. {
  113.     OSStatus    err;
  114.     
  115.     if ( control == nil )
  116.         return paramErr;
  117.         
  118.     if ( filter == nil )
  119.         return paramErr;
  120.  
  121.     err = SetControlData( control, 0, kControlKeyFilterTag, sizeof( filter ),
  122.             (Ptr)&filter );
  123.     
  124.     return err;
  125. }
  126.  
  127. //—————————————————————————————————————————————————————————————————————————————
  128. //    • SetEditTextSelection
  129. //—————————————————————————————————————————————————————————————————————————————
  130. //    Sets the selection of an edit text control and redraws it.
  131. //
  132. pascal OSStatus
  133. SetEditTextSelection( ControlHandle control, SInt16 selStart, SInt16 selEnd )
  134. {
  135.     ControlEditTextSelectionRec    selection;
  136.     OSStatus    err;
  137.  
  138.     if ( control == nil )
  139.         return paramErr;
  140.         
  141.     selection.selStart = selStart;
  142.     selection.selEnd = selEnd;
  143.     
  144.     err = SetControlData( control, 0, kControlEditTextSelectionTag,
  145.             sizeof( selection ), (Ptr)&selection );
  146.     
  147.     if ( err == noErr )
  148.         DrawOneControl( control );
  149.     
  150.     return err;
  151. }
  152.  
  153. //—————————————————————————————————————————————————————————————————————————————
  154. //    • GetEditTextSelection
  155. //—————————————————————————————————————————————————————————————————————————————
  156. //    Returns the selection for an edit text control.
  157. //
  158. pascal OSStatus
  159. GetEditTextSelection( ControlHandle control, SInt16* selStart, SInt16* selEnd )
  160. {
  161.     ControlEditTextSelectionRec    selection;
  162.     Size        actualSize;
  163.     OSStatus    err;
  164.     
  165.     if ( control == nil )
  166.         return paramErr;
  167.         
  168.     if ( selStart == nil )
  169.         return paramErr;
  170.         
  171.     if ( selEnd == nil )
  172.         return paramErr;
  173.         
  174.     err = GetControlData( control, 0, kControlEditTextSelectionTag,
  175.             sizeof( selection ), (Ptr)&selection, &actualSize );
  176.          
  177.     if ( err == noErr )
  178.     {
  179.         *selStart = selection.selStart;
  180.         *selEnd = selection.selEnd;
  181.     }
  182.         
  183.     return err;
  184. }
  185.  
  186. //—————————————————————————————————————————————————————————————————————————————
  187. //    • GetEditTextPasswordText
  188. //—————————————————————————————————————————————————————————————————————————————
  189. //    Returns the password text for an edit text password control.
  190. //
  191. pascal OSStatus
  192. GetEditTextPasswordText( ControlHandle control, StringPtr text )
  193. {
  194.     Size        actualSize;
  195.     OSStatus    err;
  196.     
  197.     if ( control == nil )
  198.         return paramErr;
  199.         
  200.     if ( text == nil )
  201.         return paramErr;
  202.  
  203.     err = GetControlData( control, 0, kControlEditTextPasswordTag,
  204.             255, (Ptr)(text+1), &actualSize );
  205.          
  206.     if ( err == noErr )
  207.         text[0] = MIN( 255, actualSize );
  208.         
  209.     return err;
  210. }
  211.  
  212. //—————————————————————————————————————————————————————————————————————————————
  213. //    • GetStaticTextText
  214. //—————————————————————————————————————————————————————————————————————————————
  215. //    Returns the text from an edit text control.
  216. //
  217. pascal OSStatus
  218. GetStaticTextText( ControlHandle control, StringPtr text )
  219. {
  220.     Size        actualSize;
  221.     OSStatus    err;
  222.     
  223.     if ( control == nil )
  224.         return paramErr;
  225.         
  226.     if ( text == nil )
  227.         return paramErr;
  228.         
  229.     err = GetControlData( control, 0, kControlStaticTextTextTag, 255, (Ptr)(text + 1), &actualSize );
  230.     if ( err == noErr )
  231.         text[0] = MIN( 255, actualSize );
  232.         
  233.     return err;
  234. }
  235.  
  236. //—————————————————————————————————————————————————————————————————————————————
  237. //    • SetStaticTextText
  238. //—————————————————————————————————————————————————————————————————————————————
  239. //    Sets the text of an edit text control and optionally redraws it.
  240. //
  241. pascal OSStatus
  242. SetStaticTextText( ControlHandle control, ConstStr255Param text, Boolean draw )
  243. {
  244.     OSStatus    err;
  245.     
  246.     if ( control == nil )
  247.         return paramErr;
  248.  
  249.     err = SetControlData( control, 0, kControlStaticTextTextTag, text[0], (Ptr)(text+1) );
  250.     if ( (err == noErr) && draw )
  251.         DrawOneControl( control );
  252.     
  253.     return err;
  254. }
  255.  
  256. //—————————————————————————————————————————————————————————————————————————————
  257. //    • GetStaticTextTextHeight
  258. //—————————————————————————————————————————————————————————————————————————————
  259. //    Returns the actual height of the text, not the control height.
  260. //
  261. pascal OSStatus
  262. GetStaticTextTextHeight( ControlHandle control, SInt16* height )
  263. {
  264.     Size        actualSize;
  265.     OSStatus    err;
  266.     
  267.     if ( control == nil )
  268.         return paramErr;
  269.         
  270.     if ( height == nil )
  271.         return paramErr;
  272.         
  273.     err = GetControlData( control, 0, kControlStaticTextTextHeightTag, sizeof( SInt16 ),
  274.          (Ptr)height, &actualSize );
  275.         
  276.     return err;
  277. }
  278.  
  279. //—————————————————————————————————————————————————————————————————————————————
  280. //    • SetProgressIndicatorState
  281. //—————————————————————————————————————————————————————————————————————————————
  282. //    Sets a progress bar to the determinate or indeterminate state.
  283. //
  284. pascal OSStatus
  285. SetProgressIndicatorState( ControlHandle control, Boolean isDeterminate )
  286. {
  287.     OSStatus    err;
  288.     Boolean        state;
  289.     
  290.     if ( control == nil )
  291.         return paramErr;
  292.  
  293.     state = !isDeterminate;    
  294.     err = SetControlData( control, 0, kControlProgressBarIndeterminateTag, sizeof( state ),
  295.             (Ptr)&state );
  296.     
  297.     return err;
  298. }
  299.  
  300. //—————————————————————————————————————————————————————————————————————————————
  301. //    • GetProgressIndicatorState
  302. //—————————————————————————————————————————————————————————————————————————————
  303. //    Returns the state of the button's default status.
  304. //
  305. pascal OSStatus
  306. GetProgressIndicatorState( ControlHandle control, Boolean* isDeterminate )
  307. {
  308.     Size        actualSize;
  309.     OSStatus    err;
  310.     Boolean        temp;
  311.     
  312.     if ( control == nil )
  313.         return paramErr;
  314.         
  315.     if ( isDeterminate == nil )
  316.         return paramErr;
  317.         
  318.     err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( temp ),
  319.              (Ptr)&temp, &actualSize );
  320.     
  321.     if ( err == noErr )
  322.         *isDeterminate = !temp;
  323.         
  324.     return err;
  325. }
  326.  
  327. //—————————————————————————————————————————————————————————————————————————————
  328. //    • SetPushButtonDefaultState
  329. //—————————————————————————————————————————————————————————————————————————————
  330. //    Sets a push button's default flag. This lets the button know whether or not
  331. //    to draw its default ring.
  332. //
  333. pascal OSStatus
  334. SetPushButtonDefaultState( ControlHandle control, Boolean isDefault )
  335. {
  336.     OSStatus    err;
  337.     
  338.     if ( control == nil )
  339.         return paramErr;
  340.  
  341.     err = SetControlData( control, 0, kControlPushButtonDefaultTag, sizeof( isDefault ),
  342.             (Ptr)&isDefault );
  343.     
  344.     return err;
  345. }
  346.  
  347. //—————————————————————————————————————————————————————————————————————————————
  348. //    • GetPushButtonDefaultState
  349. //—————————————————————————————————————————————————————————————————————————————
  350. //    Returns the state of the button's default status.
  351. //
  352. pascal OSStatus
  353. GetPushButtonDefaultState( ControlHandle control, Boolean* isDefault )
  354. {
  355.     Size        actualSize;
  356.     OSStatus    err;
  357.     
  358.     if ( control == nil )
  359.         return paramErr;
  360.         
  361.     if ( isDefault == nil )
  362.         return paramErr;
  363.         
  364.     err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( Boolean ),
  365.              (Ptr)isDefault, &actualSize );
  366.         
  367.     return err;
  368. }
  369.  
  370. //—————————————————————————————————————————————————————————————————————————————
  371. //    • GetListBoxListHandle
  372. //—————————————————————————————————————————————————————————————————————————————
  373. //    Returns the list handle from a list box control.
  374. //
  375. pascal OSStatus
  376. GetListBoxListHandle( ControlHandle control, ListHandle* list )
  377. {
  378.     Size        actualSize;
  379.     OSStatus    err;
  380.     
  381.     if ( control == nil )
  382.         return paramErr;
  383.         
  384.     if ( list == nil )
  385.         return paramErr;
  386.         
  387.     err = GetControlData( control, 0, kControlListBoxListHandleTag, sizeof( ListHandle ),
  388.              (Ptr)list, &actualSize );
  389.         
  390.     return err;
  391. }
  392.  
  393. //—————————————————————————————————————————————————————————————————————————————
  394. //    • SetListBoxKeyFilter
  395. //—————————————————————————————————————————————————————————————————————————————
  396. //    Sets the key filter for a list box control.
  397. //
  398. pascal OSStatus
  399. SetListBoxKeyFilter( ControlHandle control, ControlKeyFilterUPP filter )
  400. {
  401.     OSStatus    err;
  402.     
  403.     if ( control == nil )
  404.         return paramErr;
  405.     
  406.     if ( filter == nil )
  407.         return paramErr;
  408.  
  409.     err = SetControlData( control, 0, kControlKeyFilterTag, sizeof( filter ),
  410.             (Ptr)&filter );
  411.     
  412.     return err;
  413. }
  414.  
  415. //—————————————————————————————————————————————————————————————————————————————
  416. //    • SetIconControlTransform
  417. //—————————————————————————————————————————————————————————————————————————————
  418. //    Sets the transform for an icon control.
  419. //
  420. pascal OSStatus
  421. SetIconControlTransform( ControlHandle control, IconTransformType transform )
  422. {
  423.     OSStatus    err;
  424.     
  425.     if ( control == nil )
  426.         return paramErr;
  427.     
  428.     err = SetControlData( control, 0, kControlIconTransformTag, sizeof( transform ),
  429.             (Ptr)&transform );
  430.     
  431.     return err;
  432. }
  433.  
  434. //—————————————————————————————————————————————————————————————————————————————
  435. //    • SetIconControlAlignment
  436. //—————————————————————————————————————————————————————————————————————————————
  437. //    Sets the alignment for an icon control.
  438. //
  439. pascal OSStatus
  440. SetIconControlAlignment( ControlHandle control, IconAlignmentType align )
  441. {
  442.     OSStatus    err;
  443.     
  444.     if ( control == nil )
  445.         return paramErr;
  446.     
  447.     err = SetControlData( control, 0, kControlIconAlignmentTag, sizeof( align ),
  448.             (Ptr)&align );
  449.     
  450.     return err;
  451. }
  452.  
  453. //—————————————————————————————————————————————————————————————————————————————
  454. //    • SetClockDateTime
  455. //—————————————————————————————————————————————————————————————————————————————
  456. //    Sets the time for a clock control.
  457. //
  458. pascal OSStatus
  459. SetClockDateTime( ControlHandle control, const LongDateRec* time )
  460. {
  461.     OSStatus    err;
  462.     
  463.     if ( control == nil )
  464.         return paramErr;
  465.     
  466.     err = SetControlData( control, 0, kControlClockLongDateTag,
  467.             sizeof( LongDateRec ), (Ptr)time );
  468.     
  469.     return err;
  470. }
  471.  
  472. //—————————————————————————————————————————————————————————————————————————————
  473. //    • GetClockDateTime
  474. //—————————————————————————————————————————————————————————————————————————————
  475. //    Returns the time from a clock control.
  476. //
  477. pascal OSStatus
  478. GetClockDateTime( ControlHandle control, LongDateRec* time )
  479. {
  480.     Size        actualSize;
  481.     OSStatus    err;
  482.     
  483.     if ( control == nil )
  484.         return paramErr;
  485.         
  486.     if ( time == nil )
  487.         return paramErr;
  488.         
  489.     err = GetControlData( control, 0, kControlClockLongDateTag,
  490.             sizeof( LongDateRec ), (Ptr)time, &actualSize );
  491.         
  492.     return err;
  493. }
  494.  
  495. //——————————————————————————————————————————————————————————————————————————————————————————————————————
  496. //
  497. // • BEVEL BUTTON ROUTINES
  498. //
  499. //——————————————————————————————————————————————————————————————————————————————————————————————————————
  500.  
  501. //=========================================================================================
  502. //    • GetBevelButtonMenuValue                                                        PUBLIC
  503. //=========================================================================================
  504. //    Returns the current menuValue of the bevel button, if any. If the bevel button supports
  505. //    multivalued menus, it will return the last one chosen.
  506. //
  507. pascal OSErr
  508. GetBevelButtonMenuValue( ControlRef button, SInt16* value )
  509. {
  510.     OSErr        err;
  511.     
  512.     ASSERT_GOTO( button != nil, noButton );
  513.  
  514.     err = GetControlData( button, 0, kControlBevelButtonMenuValueTag, sizeof( SInt16 ),
  515.                         (Ptr)value, nil );
  516.     
  517.     return err;
  518.  
  519. noButton:
  520.     return paramErr;
  521. }
  522.  
  523. //=========================================================================================
  524. //    • SetBevelButtonMenuValue                                                        PUBLIC
  525. //=========================================================================================
  526. //    Sets the current value of the menu.
  527. //
  528. pascal OSErr
  529. SetBevelButtonMenuValue( ControlRef button, SInt16 value )
  530. {
  531.     OSErr        err;
  532.     
  533.     ASSERT_GOTO( button != nil, noButton );
  534.  
  535.     err = SetControlData( button, 0, kControlBevelButtonMenuValueTag, sizeof( SInt16 ),
  536.                         (Ptr)&value );
  537.     
  538.     return err;
  539.  
  540. noButton:
  541.     return paramErr;
  542. }
  543.  
  544. //=========================================================================================
  545. //    • GetBevelButtonMenuHandle                                                        PUBLIC
  546. //=========================================================================================
  547. //    Returns the current menuHandle of the bevel button, if any.
  548. //
  549. pascal OSErr
  550. GetBevelButtonMenuHandle( ControlRef button, MenuHandle* handle )
  551. {
  552.     OSErr        err;
  553.     
  554.     ASSERT_GOTO( button != nil, noButton );
  555.  
  556.     err = GetControlData( button, 0, kControlBevelButtonMenuHandleTag, sizeof( MenuHandle ),
  557.                         (Ptr)handle, nil );
  558.     
  559.     return err;
  560.  
  561. noButton:
  562.     return paramErr;
  563. }
  564.  
  565. //=========================================================================================
  566. //    • GetBevelButtonContentInfo                                                    PUBLIC
  567. //=========================================================================================
  568. //    Returns the current type of data we are displaying and the handle to that data.
  569. //
  570. pascal OSErr
  571. GetBevelButtonContentInfo( ControlRef button, const ControlButtonContentInfoPtr info )
  572. {
  573.     OSErr        err;
  574.     
  575.     ASSERT_GOTO( button != nil, noButton );
  576.  
  577.     err = GetControlData( button, 0, kControlBevelButtonContentTag, sizeof( ControlButtonContentInfo ),
  578.                         (Ptr)info, nil );
  579.     
  580.     return err;
  581.  
  582. noButton:
  583.     return paramErr;
  584. }
  585.  
  586. //=========================================================================================
  587. //    • SetBevelButtonContentInfo                                                    PUBLIC
  588. //=========================================================================================
  589. //    Sets the current content type and data for the button's content. If the current content
  590. //    was created by the button (i.e. resource based) it is disposed.
  591. //
  592. pascal OSErr
  593. SetBevelButtonContentInfo( ControlRef button, ControlButtonContentInfoPtr info )
  594. {
  595.     OSErr        err;
  596.     
  597.     ASSERT_GOTO( button != nil, noButton );
  598.  
  599.     err = SetControlData( button, 0, kControlBevelButtonContentTag, sizeof( ControlButtonContentInfo ),
  600.                 (Ptr)info );
  601.  
  602.     return err;
  603.     
  604. noButton:
  605.     return paramErr;
  606. }
  607.  
  608. //=========================================================================================
  609. //    • SetBevelButtonTransform                                                        PUBLIC
  610. //=========================================================================================
  611. //    Sets the transform that will be OR'ed into the calculated transform for the icon. This
  612. //    can be used to add a label color or an offline attribute, etc.
  613. //
  614. pascal OSErr
  615. SetBevelButtonTransform( ControlRef button, IconTransformType transform )
  616. {
  617.     OSErr        err;
  618.     
  619.     ASSERT_GOTO( button != nil, noButton );
  620.  
  621.     err = SetControlData( button, 0, kControlBevelButtonTransformTag, sizeof( transform ), (Ptr)&transform );
  622.  
  623.     return err;
  624.     
  625. noButton:
  626.     return paramErr;
  627. }
  628.  
  629. //=========================================================================================
  630. //    • SetBevelButtonTextOptions                                                        PUBLIC
  631. //=========================================================================================
  632. //    Sets the current text options.
  633. //
  634. pascal OSErr
  635. SetBevelButtonTextAlignment( ControlRef button, ControlButtonTextAlignment align, SInt16 hOffset )
  636. {
  637.     OSErr        err;
  638.     
  639.     ASSERT_GOTO( button != nil, noButton );
  640.  
  641.     err = SetControlData( button, 0, kControlBevelButtonTextAlignTag, sizeof( ControlButtonTextAlignment ),
  642.                         (Ptr)&align );
  643.  
  644.     if ( err == noErr )
  645.     {
  646.         err = SetControlData( button, 0, kControlBevelButtonTextOffsetTag, sizeof( SInt16 ),
  647.                         (Ptr)&hOffset );
  648.     }
  649.     return err;
  650.     
  651. noButton:
  652.     return paramErr;
  653. }
  654.  
  655. //=========================================================================================
  656. //    • SetBevelButtonGraphicAlignment                                                PUBLIC
  657. //=========================================================================================
  658. //    Sets the aligment options for the button graphic.
  659. //
  660. pascal OSErr
  661. SetBevelButtonGraphicAlignment( ControlRef button, ControlButtonGraphicAlignment align, SInt16 hOffset, SInt16 vOffset )
  662. {
  663.     OSErr        err;
  664.     Point        offset;
  665.     
  666.     ASSERT_GOTO( button != nil, noButton );
  667.  
  668.     ASSERT_ALIGNMENT( align );
  669.  
  670.     
  671.     ASSERT( hOffset >= 0 );
  672.     ASSERT( vOffset >= 0 );
  673.     
  674.     err = SetControlData( button, 0, kControlBevelButtonGraphicAlignTag, sizeof( ControlButtonGraphicAlignment ),
  675.                         (Ptr)&align );
  676.  
  677.     if ( err == noErr )
  678.     {
  679.         offset.h = hOffset;
  680.         offset.v = vOffset;
  681.         
  682.         err = SetControlData( button, 0, kControlBevelButtonGraphicOffsetTag, sizeof( Point ),
  683.                         (Ptr)&offset );
  684.     }
  685.  
  686.     return err;
  687.     
  688. noButton:
  689.     return paramErr;
  690. }
  691.  
  692. //=========================================================================================
  693. //    • SetBevelButtonTextPlacement                                                    PUBLIC
  694. //=========================================================================================
  695. //    Sets the text placement for buttons with a combination of text and a graphic. This
  696. //    routine also sets the alignment to the proper alignment based on the current graphic
  697. //    alignment.
  698. //
  699. pascal OSErr
  700. SetBevelButtonTextPlacement( ControlRef button, ControlButtonTextPlacement where )
  701. {
  702.     OSErr        err;
  703.     
  704.     ASSERT_GOTO( button != nil, noButton );
  705.  
  706.     err = SetControlData( button, 0, kControlBevelButtonTextPlaceTag, sizeof( ControlButtonTextPlacement ),
  707.                 (Ptr)&where );
  708.  
  709.     return err;
  710.     
  711. noButton:
  712.     return paramErr;
  713. }
  714.  
  715. //=========================================================================================
  716. //    • GetImageWellContentInfo                                                        PUBLIC
  717. //=========================================================================================
  718. //    Returns the current type of data we are displaying and the handle to that data.
  719. //
  720. pascal OSErr
  721. GetImageWellContentInfo( ControlRef button, const ControlButtonContentInfoPtr info )
  722. {
  723.     OSErr        err;
  724.     
  725.     ASSERT_GOTO( button != nil, noButton );
  726.  
  727.     err = GetControlData( button, 0, kControlImageWellContentTag, sizeof( ControlButtonContentInfo ),
  728.                         (Ptr)info, nil );
  729.     
  730.     return err;
  731.  
  732. noButton:
  733.     return paramErr;
  734. }
  735.  
  736. //=========================================================================================
  737. //    • SetImageWellContentInfo                                                        PUBLIC
  738. //=========================================================================================
  739. //    Sets the current content type and data for the button's content. If the current content
  740. //    was created by the button (i.e. resource based) it is disposed.
  741. //
  742. pascal OSErr
  743. SetImageWellContentInfo( ControlRef button, ControlButtonContentInfoPtr info )
  744. {
  745.     OSErr        err;
  746.     
  747.     ASSERT_GOTO( button != nil, noButton );
  748.  
  749.     err = SetControlData( button, 0, kControlImageWellContentTag, sizeof( ControlButtonContentInfo ), (Ptr)info );
  750.  
  751.     return err;
  752.     
  753. noButton:
  754.     return paramErr;
  755. }
  756.  
  757. //=========================================================================================
  758. //    • SetImageWellTransform                                                            PUBLIC
  759. //=========================================================================================
  760. //    Sets the transform that will be OR'ed into the calculated transform for the icon. This
  761. //    can be used to add a label color or an offline attribute, etc.
  762. //
  763. pascal OSErr
  764. SetImageWellTransform( ControlRef button, IconTransformType transform )
  765. {
  766.     OSErr        err;
  767.     
  768.     ASSERT_GOTO( button != nil, noButton );
  769.  
  770.     err = SetControlData( button, 0, kControlImageWellTransformTag, sizeof( transform ), (Ptr)&transform );
  771.  
  772.     return err;
  773.     
  774. noButton:
  775.     return paramErr;
  776. }
  777.  
  778. //=========================================================================================
  779. //    • GetTabContentRect                                                                PUBLIC
  780. //=========================================================================================
  781. //    Gets the content area of a tab control.
  782. //
  783. pascal OSErr
  784. GetTabContentRect( ControlRef tabControl, Rect* contentRect )
  785. {
  786.     OSErr        err;
  787.     
  788.     ASSERT_GOTO( tabControl != nil, noButton );
  789.  
  790.     err = GetControlData( tabControl, 0, kControlTabContentRectTag, sizeof( Rect ),
  791.                         (Ptr)contentRect, nil );
  792.     
  793.     return err;
  794.  
  795. noButton:
  796.     return paramErr;
  797. }
  798.  
  799. //=========================================================================================
  800. //    • SetTabEnabled                                                                    PUBLIC
  801. //=========================================================================================
  802. //    Sets the hilite flag of a particular tab of a tab control.
  803. //
  804. pascal OSErr
  805. SetTabEnabled( ControlRef tabControl, SInt16 tabToHilite, Boolean enabled )
  806. {
  807.     OSErr        err;
  808.     
  809.     ASSERT_GOTO( tabControl != nil, noButton );
  810.  
  811.     err = SetControlData( tabControl, tabToHilite, kControlTabEnabledFlagTag, sizeof( Boolean ),
  812.                         (Ptr)&enabled );
  813.     
  814.     return err;
  815.  
  816. noButton:
  817.     return paramErr;
  818. }
  819.  
  820. //=========================================================================================
  821. //    • SetDisclosureTriangleLastValue                                                PUBLIC
  822. //=========================================================================================
  823. //    Sets the 'last value' field of a disclosure triangle. This is useful.
  824. //
  825. pascal OSErr
  826. SetDisclosureTriangleLastValue( ControlRef triangle, SInt16 value )
  827. {
  828.     OSErr        err;
  829.     
  830.     ASSERT_GOTO( triangle != nil, noButton );
  831.  
  832.     err = SetControlData( triangle, 0, kControlTriangleLastValueTag, sizeof( SInt16 ), (Ptr)&value );
  833.     
  834.     return err;
  835.  
  836. noButton:
  837.     return paramErr;
  838. }
  839.  
  840.